import lang from '@/lang';
import locale from 'element-ui/lib/locale';

const language = {
  state: {
    // 语言
    language: localStorage.getItem('language') || 'zh',
  },
  mutations: {
    SET_LANGUAGE(state, val) {
      localStorage.setItem('language', val);
      locale.i18n((key, value) => lang.t(key, value));
      lang.locale = val;
      state.language = val;
      const launcher = document.getElementById('launcher');
      if (launcher) {
        launcher.style.visibility = val !== 'zh' ? 'hidden' : 'initial';
      }
    },
  },
};
export default language;
